package com.test.activemq.simple;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;

public class Sender {

	public static void main(String[] args) throws JMSException, InterruptedException {

//		ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://192.168.180.129:61616");
		ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");

		Connection connection = factory.createConnection();
		connection.start();

		Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);

		Queue queue = session.createQueue("20190319");

		MessageProducer producer = session.createProducer(queue);

		// 设置消息头
		// producer.setDeliveryMode(deliveryMode);

		for (int i = 0; i < 3; i++) {

			// 消息体
			Message msg = session.createTextMessage("哈喽，大家好！" + i);

			// 消息属性
			msg.setBooleanProperty("是否真诚", false);

			Thread.sleep(1000);
			
//			void send(Destination destination,Message message,int deliveryMode,int priority,long timeToLive)throws JMSException;
			producer.send(msg);

		}

		session.commit();
		session.close();
		connection.close();
	}
}
